//
//  MineViewController.m
//  Shine
//
//  Created by 王斌 on 16/3/9.
//  Copyright © 2016年 王斌. All rights reserved.
//

#import "MineViewController.h"
#import "MineLeftHeadCVCell.h"
#import "MineMidHeadCVCell.h"
#import "MineRightHeadCVCell.h"
#import "MineNoSetTVCell.h"
#import "MineSetTVCell.h"
#import "MineWeightDatePickerView.h"
#import "YJW_DatePickerView.h"
#import "MineTargetWeightTVCell.h"
#import "MineTargetWeightView.h"
#import "MineBMIView.h"

@interface MineViewController ()<UITableViewDelegate, UITableViewDataSource, UICollectionViewDataSource, UICollectionViewDelegate>
@property(nonatomic, strong)UITableView *tableViewMine;
@property(nonatomic, strong)UICollectionView *collectionViewHead;
@property(nonatomic, strong)UIView *viewHead;
@property(nonatomic, strong)UIPageControl *pageControlHead;
@property(nonatomic, assign)BOOL isSelected;
@property(nonatomic, strong)MineWeightDatePickerView *viewSet;
@property(nonatomic, strong)YJW_DatePickerView *datePickerView;
@property(nonatomic, strong)MineTargetWeightView *targetView;
@property(nonatomic, strong)CoreDataManager *coreDataManager;
@property(nonatomic, strong)NSArray *coreArr;
@property(nonatomic, assign)NSInteger count;
@property(nonatomic, strong)MineBMIView *BMIView;
@end

@implementation MineViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Do any additional setup after loading the view from its nib.
    
    self.title = @"我";
    // 创建tableView
    [self createTableViewMine];
    // 创建tableView头视图
    [self createTableViewHead];
    
    // 如果程序设置完体重的button再运行程序_isSelected = YES, 也就是创建第二个cell
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    if ([userDefaults objectForKey:@"setp"] == nil) {
        [userDefaults setBool:NO forKey:@"setp"];
        _isSelected = NO;
    } else {
        _isSelected = YES;
    }
    
    // 在self.view上添加个手势
    UITapGestureRecognizer *tapView = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapView:)];
    [self.view addGestureRecognizer:tapView];
    
    self.coreDataManager = [CoreDataManager shareInstance];
    // 获取步数
    [self createStepNumber];
    
}

#pragma mark 获取步数
// 获取步数
- (void)createStepNumber{
    self.coreArr = [self.coreDataManager selectSevenDay];
    self.count = 0;
    for (HealthKit *temp in self.coreArr) {
        self.count += [temp.count integerValue];
    }
}

// 在self.view上添加个手势
- (void)tapView:(UITapGestureRecognizer *)tap{
    [self.viewSet removeFromSuperview];
    UIVisualEffectView *effect = (UIVisualEffectView *)[self.view viewWithTag:1001];
    [effect removeFromSuperview];
    [self.targetView removeFromSuperview];
    [self.BMIView removeFromSuperview];
}
# pragma mark 创建头视图
// 创建头视图(UICollectionView)
- (void)createTableViewHead{
    
    self.viewHead = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH_SCREEN, 200)];
//    self.viewHead = [[UIView alloc] init];
    
    UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc] init];
    flow.itemSize = CGSizeMake(WIDTH_SCREEN, 200);
    flow.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    flow.minimumLineSpacing = 0;
    
    self.collectionViewHead = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, WIDTH_SCREEN, 200) collectionViewLayout:flow];
//    self.collectionViewHead = [[UICollectionView alloc] init];
//    [self.collectionViewHead setCollectionViewLayout:flow];
    self.collectionViewHead.delegate = self;
    self.collectionViewHead.dataSource = self;
    self.collectionViewHead.contentOffset = CGPointMake(WIDTH_SCREEN, 0);
    self.collectionViewHead.pagingEnabled = YES;
    self.collectionViewHead.bounces = NO;
    self.collectionViewHead.showsHorizontalScrollIndicator = NO;
    [self.collectionViewHead registerClass:[MineLeftHeadCVCell class] forCellWithReuseIdentifier:@"left"];
    [self.collectionViewHead registerClass:[MineMidHeadCVCell class] forCellWithReuseIdentifier:@"mid"];
    [self.collectionViewHead registerClass:[MineRightHeadCVCell class] forCellWithReuseIdentifier:@"right"];
    
    NSIndexPath *indexPath = [NSIndexPath indexPathForItem:0 inSection:0];
    [self.collectionViewHead scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
    [self.viewHead addSubview:self.collectionViewHead];
    self.tableViewMine.tableHeaderView = self.viewHead;
    
    self.pageControlHead = [[UIPageControl alloc] init];
//    self.pageControlHead.center = CGPointMake(WIDTH_SCREEN/2, 180);
    self.pageControlHead.numberOfPages = 3;
    self.pageControlHead.pageIndicatorTintColor = [UIColor lightGrayColor];
    self.pageControlHead.currentPageIndicatorTintColor = COLORYELLO;
    [self.viewHead addSubview:self.pageControlHead];
    
    [self.pageControlHead addTarget:self action:@selector(pageChange:) forControlEvents:UIControlEventValueChanged];
    
//    [self.viewHead mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.mas_equalTo(0);
//        make.left.mas_equalTo(0);
//        make.width.mas_equalTo(WIDTH_SCREEN);
//        make.height.mas_equalTo(200);
//    }];
    
//    [self.collectionViewHead mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.mas_equalTo(0);
//        make.left.mas_equalTo(0);
//        make.width.mas_equalTo(WIDTH_SCREEN);
//        make.height.mas_equalTo(200);
//    }];
    
    [self.pageControlHead mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(180);
        make.left.mas_equalTo(150);
        make.width.mas_equalTo(100);
        make.height.mas_equalTo(20);
    }];
}

// collectionViewHead滑动结束page跟着变
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    self.pageControlHead.currentPage = self.collectionViewHead.contentOffset.x/WIDTH_SCREEN;
}
// pageControlHead的方法, 当page改变collectionViewHead的偏移量也变
- (void)pageChange:(UIPageControl *)page{
    self.collectionViewHead.contentOffset = CGPointMake(page.currentPage*WIDTH_SCREEN, 0);
}
# pragma mark 创建TableView
// 创建tableView
- (void)createTableViewMine{
//    self.tableViewMine = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
    self.tableViewMine = [[UITableView alloc] init];
    [self.view addSubview:self.tableViewMine];
    [self.tableViewMine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self.view);
    }];
    self.tableViewMine.backgroundColor = COLORBLACK;
    self.tableViewMine.delegate = self;
    self.tableViewMine.dataSource = self;
    
    self.tableViewMine.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    [self.tableViewMine registerClass:[MineNoSetTVCell class] forCellReuseIdentifier:@"reuse"];
    
    [self.tableViewMine registerClass:[MineSetTVCell class] forCellReuseIdentifier:@"set"];
    
    [self.tableViewMine registerClass:[MineTargetWeightTVCell class] forCellReuseIdentifier:@"target"];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 3;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.item == 0) {
        MineLeftHeadCVCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"left" forIndexPath:indexPath];
        cell.titleLabel.text = @"加油阿 ! 徐徐图之, 乃真达标也!";
        cell.titleLabel.textColor = [UIColor lightGrayColor];
        [cell.buttonImage setTitle:@"button" forState:UIControlStateNormal];
        cell.kcalNumberLabel.text = [NSString stringWithFormat:@"%.f", self.count / 38.0];
        cell.kcalNumberLabel.textColor = COLORYELLO;
        cell.kcalLabel.text = @"大卡-本周";
        cell.kcalLabel.textColor = [UIColor whiteColor];
        cell.progressView.progress = self.count / 38.0 / 904;
        cell.progressView.progressTintColor = COLORYELLO;
        cell.progressView.trackTintColor = [UIColor lightGrayColor];
        cell.progressView.progressViewStyle = UIProgressViewStyleBar;
        cell.objectivesLabel.text = @"基础目标:904大卡";
        cell.objectivesLabel.textColor = [UIColor lightGrayColor];
        cell.contentView.backgroundColor = COLORBLACK;
        return cell;
    } else if(indexPath.item == 1){
        MineMidHeadCVCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"mid" forIndexPath:indexPath];
        cell.leftTopLabel.text = @"最近您击败了";
        cell.leftTopLabel.textColor = [UIColor lightGrayColor];
        cell.leftMidLabel.text = @"100%";
        cell.leftMidLabel.textColor = COLORYELLO;
        cell.leftMidLabel.font = [UIFont systemFontOfSize:40];
        cell.leftBottomLabel.text = @"的全国用户";
        cell.leftBottomLabel.textColor = [UIColor lightGrayColor];
        cell.rightTopLabel.text = @"您的活力指数";
        cell.rightTopLabel.textColor = [UIColor lightGrayColor];
        cell.rightMidLabel.text = @"18岁";
        cell.rightMidLabel.font = [UIFont systemFontOfSize:40];
        cell.rightMidLabel.textColor = COLORYELLO;
        cell.rightBottomLabel.text = @"岁月是把杀猪刀";
        cell.rightBottomLabel.textColor = [UIColor lightGrayColor];
        cell.midLineView.backgroundColor = [UIColor blackColor];
        cell.contentView.backgroundColor = COLORBLACK;
        return cell;
    } else {
        MineRightHeadCVCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"right" forIndexPath:indexPath];
        cell.totalLabel.text = @"生涯合计";
        cell.totalLabel.textColor = [UIColor lightGrayColor];
        cell.stepNumberLabel.text = [NSString stringWithFormat:@"%ld", self.count];
        cell.stepNumberLabel.font = [UIFont systemFontOfSize:40];
        cell.stepNumberLabel.textColor = COLORYELLO;
        cell.stepLabel.text = @"步";
        cell.stepLabel.textColor = [UIColor lightGrayColor];
        cell.kilocalorieLabel.text = @"大卡";
        cell.kilocalorieLabel.textColor = [UIColor lightGrayColor];
        // 大卡赋值
        cell.kilocalorieNumberLabel.text = [NSString stringWithFormat:@"%.f", self.count / 38.0];
        cell.kilocalorieNumberLabel.font = [UIFont systemFontOfSize:30];
        cell.kilocalorieNumberLabel.textColor = COLORYELLO;
        cell.kilometreLabel.text = @"公里";
        cell.kilometreLabel.textColor = [UIColor lightGrayColor];
        // 公里
        cell.kilometreNumberLabel.text = [NSString stringWithFormat:@"%ld", self.count / 1464];
        cell.kilometreNumberLabel.textColor = COLORYELLO;
        cell.kilometreNumberLabel.font = [UIFont systemFontOfSize:30];
        cell.hourLabel.text = @"小时";
        cell.hourLabel.textColor = [UIColor lightGrayColor];
        // 时间
        NSInteger h = self.count / 104 / 60;
        cell.hourNumberLabel.text = [NSString stringWithFormat:@"%ld", h];
        cell.hourNumberLabel.textColor = COLORYELLO;
        cell.hourNumberLabel.font = [UIFont systemFontOfSize:30];
        cell.contentView.backgroundColor = COLORBLACK;
        return cell;
    }
}
# pragma mark tableView行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (_isSelected) {
        return 175;
    } else {
        return HEIGHT_SCREEN-200-44-64;
    }
}
# pragma mark tableView行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (_isSelected) {
        return 2;
    } else {
        return 1;
    }
}
# pragma mark tableView赋值
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (!_isSelected) {
        MineNoSetTVCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse" forIndexPath:indexPath];
        NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
        if ([userDefaults objectForKey:@"set"] == nil) {
            [userDefaults setBool:NO forKey:@"set"];
            cell.noWeightLabel.text = @"您还没有记录体重";
            cell.noWeightLabel.textColor = [UIColor lightGrayColor];
            cell.personImageView.backgroundColor = [UIColor cyanColor];
            [cell.buttonSetWeight setTitle:@"0.0" forState:UIControlStateNormal];
            [cell.buttonSetWeight addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
            cell.titleWeightLabel.text = @"从今天开始记录体重变化吧";
            cell.titleWeightLabel.textColor = [UIColor lightGrayColor];
            cell.contentView.backgroundColor = COLORBLACK;
            cell.tag = 1000;
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        return cell;
    } else {
        if (indexPath.row == 0) {
            MineSetTVCell *cell = [tableView dequeueReusableCellWithIdentifier:@"set" forIndexPath:indexPath];
            cell.nowWeightLabel.text = @"当前体重";
            cell.nowWeightLabel.textColor = [UIColor lightGrayColor];
            cell.nowWeightNumberLabel.tag = 4000;
#warning 在这调用sandBox的方法给label赋值
            cell.nowWeightNumberLabel.text = [self sandBox];
            CGFloat weightSet = [self.viewSet.textFieldNumber.text floatValue];
            cell.nowWeightNumberLabel.textColor = COLORYELLO;
            cell.nowWeightNumberLabel.font = [UIFont systemFontOfSize:40];
#warning 给nowWeightNumberLabel添加双击手势
            cell.nowWeightNumberLabel.userInteractionEnabled = YES;
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickAction:)];
            // 把手势添加到视图上去
            [cell.nowWeightNumberLabel addGestureRecognizer:tap];
            // 触发方法需要点击几次,默认是1
            tap.numberOfTapsRequired = 2;
            [cell.buttonSetWeight setTitle:@"-.-" forState:UIControlStateNormal];
            [cell.buttonSetWeight addTarget:self action:@selector(clickAction:) forControlEvents:UIControlEventTouchUpInside];
            cell.hiddenLabel.tag = 2000;
            cell.hiddenLabel.textColor = [UIColor whiteColor];
            cell.hiddenLabel.textAlignment = YES;
            [cell.buttonWeightChange setTitle:@"无变化" forState:UIControlStateNormal];
            [cell.buttonWeightChange setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [cell.buttonWeightChange addTarget:self action:@selector(clickLookChange:) forControlEvents:UIControlEventTouchUpInside];
            cell.buttonWeightChange.tag = 1500;
            cell.buttonWeightChange.backgroundColor = [UIColor colorWithRed:49/256.0 green:141/256.0 blue:63/256.0 alpha:1];
            cell.buttonWeightChange.layer.cornerRadius = 3;
            cell.buttonWeightChange.layer.masksToBounds = YES;
            cell.buttonWeightChange.showsTouchWhenHighlighted=YES;
            
            CGFloat heightSet = [self.BMIView.heightNumberTextField.text floatValue];
            [cell.bmiButton setTitle:[NSString stringWithFormat:@"BMI %.1f", weightSet /((heightSet/100)*(heightSet/100))] forState:UIControlStateNormal];
            [cell.bmiButton addTarget:self action:@selector(bmiAction:) forControlEvents:UIControlEventTouchUpInside];
            cell.contentView.backgroundColor = COLORBLACK;
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        } else {
            MineTargetWeightTVCell *cell = [tableView dequeueReusableCellWithIdentifier:@"target" forIndexPath:indexPath];
            [cell.targetButton setTitle:@"设置目标体重" forState:UIControlStateNormal];
            [cell.targetButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
            [cell.targetButton addTarget:self action:@selector(targetAction:) forControlEvents:UIControlEventTouchUpInside];
            [cell.imageButton setTitle:@"0.o" forState:UIControlStateNormal];
            [cell.imageButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [cell.imageButton addTarget:self action:@selector(targetAction:) forControlEvents:UIControlEventTouchUpInside];
            cell.contentView.backgroundColor = COLORBLACK;
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }
    }
}
#pragma mark BMIbutton点击方法
// BMIbutton点击方法
- (void)bmiAction:(UIButton *)button{
    UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
    UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:effect];
    effectView.frame = [UIScreen mainScreen].bounds;
    effectView.tag = 1001;
    effectView.alpha = 0.8;
    [self.view addSubview:effectView];
    self.BMIView = [[MineBMIView alloc] initWithFrame:CGRectMake(0, 0, 250, 160)];
    self.BMIView.layer.cornerRadius = 10;
    self.BMIView.layer.borderWidth = 2;
    self.BMIView.layer.masksToBounds = YES;
    self.BMIView.center = CGPointMake(WIDTH_SCREEN/2, HEIGHT_SCREEN/2-100);
    self.BMIView.heightNumberTextField.tag = 3000;
    self.BMIView.heightNumberTextField.keyboardType = UIKeyboardTypeNumberPad;
    [self.BMIView.xButton addTarget:self action:@selector(xAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.BMIView.saveButton addTarget:self action:@selector(saveAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.BMIView];
}
#pragma mark 目标体重的button点击方法
// 目标体重的button点击方法
- (void)targetAction:(UIButton *)button{
    UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
    UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:effect];
    effectView.frame = [UIScreen mainScreen].bounds;
    effectView.tag = 1001;
    effectView.alpha = 0.8;
    [self.view addSubview:effectView];
    self.targetView = [[MineTargetWeightView alloc] initWithFrame:CGRectMake(0, 0, 250, 250)];
    self.targetView.layer.cornerRadius = 10;
    self.targetView.layer.borderWidth = 2;
    self.targetView.layer.masksToBounds = YES;
    self.targetView.textFieldNumber.keyboardType = UIKeyboardTypeNumberPad;
    self.targetView.timeNumberTextField.keyboardType = UIKeyboardTypeNumberPad;
    self.targetView.center = CGPointMake(WIDTH_SCREEN/2, HEIGHT_SCREEN/2-100);
    [self.targetView.xButton addTarget:self action:@selector(xAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.targetView.saveButton addTarget:self action:@selector(saveAction:) forControlEvents:UIControlEventTouchUpInside];
    self.targetView.reduceWeightLabel.text = @"每周减重 -- kg";
    [self.view addSubview:self.targetView];
}
#pragma mark 绿色button点击方法
// 绿色button点击方法
- (void)clickLookChange:(UIButton *)button{
    [UIView animateWithDuration:2 animations:^{
        UILabel *label = (UILabel *)[self.view viewWithTag:2000];
        label.frame = CGRectMake(WIDTH_SCREEN-120, 60, 80, 20);
        label.text = @"哈哈";
    } completion:^(BOOL finished) {
        // 想让这个UIView再回去在这里在写一个UIView的动画
        [UIView animateWithDuration:2 animations:^{
            UILabel *label = (UILabel *)[self.view viewWithTag:2000];
            label.frame = CGRectMake(WIDTH_SCREEN-120, 60, 80, 0);
        }];
    }];
//    NSString*documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES) firstObject];
//    NSString*newFielPath = [documentsPath stringByAppendingPathComponent:@"weight.txt"];
//    NSString *weightStr = [NSString stringWithContentsOfFile:newFielPath encoding:NSUTF8StringEncoding error:nil];
//    NSInteger weightInt = [weightStr integerValue];
//    UILabel *labelWeight = (UILabel *)[self.view viewWithTag:4000];
//    NSInteger labelWeightInt = [labelWeight.text integerValue];
//    UIButton *buttonGreen = (UIButton *)[self.view viewWithTag:1500];
//    if (labelWeightInt > weightInt) {
//        [buttonGreen setTitle:[NSString stringWithFormat:@"%ld", weightInt - labelWeightInt] forState:UIControlStateNormal];
//    } else if (labelWeightInt < weightInt) {
//        [buttonGreen setTitle:[NSString stringWithFormat:@"%ld", weightInt - labelWeightInt] forState:UIControlStateNormal];
//        buttonGreen.backgroundColor = [UIColor redColor];
//    }
}
#pragma mark 没设置体重时的button点击方法
// 没设置体重时的button点击方法
- (void)click:(UIButton *)button{
    UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
    UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:effect];
    effectView.frame = [UIScreen mainScreen].bounds;
    effectView.tag = 1001;
    effectView.alpha = 0.8;
    [self.view addSubview:effectView];
    self.viewSet = [[MineWeightDatePickerView alloc] initWithFrame:CGRectMake(0, 0, 250, 200)];
    self.viewSet.layer.cornerRadius = 10;
    self.viewSet.layer.borderWidth = 2;
    self.viewSet.layer.masksToBounds = YES;
    self.viewSet.textFieldNumber.keyboardType = UIKeyboardTypeNumberPad;
    self.viewSet.textFieldNumber.tag = 3001;
    self.viewSet.center = CGPointMake(WIDTH_SCREEN/2, HEIGHT_SCREEN/2-100);
    [self.viewSet.xButton addTarget:self action:@selector(xAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.viewSet.saveButton addTarget:self action:@selector(saveAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.viewSet];
    
    // 给dateClickLabel添加个手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    [self.viewSet.dateClickLabel addGestureRecognizer:tap];
    self.viewSet.dateClickLabel.userInteractionEnabled = YES;
}
#pragma mark 设置完体重的button点击方法
// 设置完体重的button点击方法
- (void)clickAction:(UIButton *)button{
    // *给视图添加一个毛玻璃效果
    UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
    UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:effect];
    effectView.frame = [UIScreen mainScreen].bounds;
    effectView.tag = 1001;
    effectView.alpha = 0.8;
    [self.view addSubview:effectView];
    self.viewSet = [[MineWeightDatePickerView alloc] initWithFrame:CGRectMake(0, 0, 250, 200)];
    self.viewSet.layer.cornerRadius = 10;
    self.viewSet.layer.borderWidth = 2;
    self.viewSet.layer.masksToBounds = YES;
    self.viewSet.textFieldNumber.keyboardType = UIKeyboardTypeNumberPad;
    self.viewSet.center = CGPointMake(WIDTH_SCREEN/2, HEIGHT_SCREEN/2-100);
    self.viewSet.textFieldNumber.tag = 3001;
    [self.viewSet.xButton addTarget:self action:@selector(xAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.viewSet.saveButton addTarget:self action:@selector(saveAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.viewSet];
    
    // 给dateClickLabel添加个手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    [self.viewSet.dateClickLabel addGestureRecognizer:tap];
    self.viewSet.dateClickLabel.userInteractionEnabled = YES;
    
}
#pragma mark button保存方法
// button保存方法
- (void)saveAction:(UIButton *)button{
    _isSelected = YES;
    
    UITextField *textField = (UITextField *)[self.view viewWithTag:3001];
    NSString*documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES) firstObject];
    NSString*newFielPath = [documentsPath stringByAppendingPathComponent:@"weight.txt"];
    [textField.text writeToFile:newFielPath atomically:YES encoding:NSUTF8StringEncoding error:nil];
    // 打印沙盒路径
    NSLog(@"%@", documentsPath);
    
    MineNoSetTVCell *cell = (MineNoSetTVCell *)[self.view viewWithTag:1000];
    [cell removeFromSuperview];
    [self.tableViewMine reloadData];
    [self.targetView removeFromSuperview];
    [self.viewSet removeFromSuperview];
    UIVisualEffectView *effect = (UIVisualEffectView *)[self.view viewWithTag:1001];
    [effect removeFromSuperview];
    [self.BMIView removeFromSuperview];
}
#pragma mark button x方法
// button x方法
- (void)xAction:(UIButton *)button{
    [self.viewSet removeFromSuperview];
    UIVisualEffectView *effect = (UIVisualEffectView *)[self.view viewWithTag:1001];
    [effect removeFromSuperview];
    [self.targetView removeFromSuperview];
    [self.BMIView removeFromSuperview];
}

- (void)tapAction:(UITapGestureRecognizer *)tap{
    self.datePickerView = [[YJW_DatePickerView alloc] initWithFrame:CGRectMake(0, 0, WIDTH_SCREEN, HEIGHT_SCREEN)];
    [self.datePickerView.buttonSure addTarget:self action:@selector(sureAction:) forControlEvents:1<<6];
    [self.datePickerView.buttonCancel addTarget:self action:@selector(cancelAction:) forControlEvents:1<<6];
    [self.view addSubview:self.datePickerView];
}

- (void)cancelAction:(UIButton *)button{
    [self.datePickerView removeFromSuperview];
}

- (void)sureAction:(UIButton *)button{
    NSString *timestamp = [self.datePickerView.dateForMatter stringFromDate:self.datePickerView.datePicker.date];
    self.viewSet.dateClickLabel.text = timestamp;
    [self.datePickerView removeFromSuperview];
}

#pragma mark viewWillAppear
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self createStepNumber];
    [self.tableViewMine reloadData];
}
# pragma mark 在沙盒里取值(在cell里调用并赋值)
- (NSString *)sandBox{
    NSString*documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES) firstObject];
    NSString*newFielPath = [documentsPath stringByAppendingPathComponent:@"weight.txt"];
    NSString *weightStr = [NSString stringWithContentsOfFile:newFielPath encoding:NSUTF8StringEncoding error:nil];
    return weightStr;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
